package com.tourism.controller;

import com.github.pagehelper.PageInfo;
import com.tourism.entity.Attraction;
import com.tourism.entity.AttractionQuery;
import com.tourism.entity.Line;
import com.tourism.exception.GlobalException;
import com.tourism.service.AttractionService;
import com.tourism.util.common.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 景点相关的控制器
 * @Author z
 * @Date 2021-03-01 20:40
 */
@Controller
@RequestMapping("/attraction")
public class AttractionController {


    @Autowired
    private AttractionService attractionService;

    /**
     * 根据景点id查询景点信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getAttractionById")
    @ResponseBody
    public Attraction getAttractionById(Long id) {
        return attractionService.getAttractionById(id);
    }
    /**
     * 根据景点id删除景点信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteAttractionById")
    @ResponseBody
    public Response deleteAttractionById(Long id) {
        return Response.success(attractionService.deleteAttractionById(id));
    }

    /**
     * 新增景点
     *
     * @param attraction
     * @return
     */
    @PostMapping("/addAttraction")
    @ResponseBody
    public Response addAttraction(@RequestBody Attraction attraction) throws GlobalException {
        return Response.success(attractionService.addAttraction(attraction));

    }
    /**
     * 修改景点
     *
     * @param attraction
     * @return
     */
    @PostMapping("/updateAttraction")
    @ResponseBody
    public Response updateAttraction(@RequestBody Attraction attraction) {
        return Response.success(attractionService.updateAttraction(attraction));

    }

    /**
     * 更新浏览量+1
     *
     * @param id
     * @return
     */
    @GetMapping("/updatePageView")
    @ResponseBody
    public Response updatePageView(Long id) {
        return Response.success(attractionService.updatePageView(id));

    }


    /**
     * 查询景点列表
     *
     * @param attractionQuery
     * @return
     */
    @PostMapping("/getAttractionList")
    @ResponseBody
    public PageInfo<Attraction> getAttractionList(@RequestBody AttractionQuery attractionQuery) {
        return attractionService.getAttractionList(attractionQuery);
    }

}
